﻿using System.Reflection;
using System.Web;
//using System.Web.Mvc;
//using System.Web.Optimization;
using System.Web.Routing;
using Abp.Localization;
using Abp.Localization.Dictionaries;
using Abp.Localization.Dictionaries.Xml;
using Abp.Modules;
using Abp.Web.Mvc;
using System.Web.Mvc;
using Abp.Configuration.Startup;
using Abp.Application.Services;
using STOWaybillMall.Products;
using Swashbuckle.Application;
using System.Linq;
using System.Web.Http;
using System.Collections.Generic;
using DapperExtensions;
using Dapper;

namespace STOWaybillMall.Web
{
    [DependsOn(
        typeof(AbpWebMvcModule),
        typeof(EntityFramework.STOWaybillMallDataModule),
        typeof(Dapper.STOWaybillMallDataModule),
        typeof(STOWaybillMallApplicationModule), 
        typeof(STOWaybillMallWebApiModule))]
    public class STOWaybillMallWebModule : AbpModule
    {
        public override void PreInitialize()
        {
            //Add/remove languages for your application
            Configuration.Localization.Languages.Add(new LanguageInfo("en", "English", "famfamfam-flag-england", true));
            Configuration.Localization.Languages.Add(new LanguageInfo("tr", "Türkçe", "famfamfam-flag-tr"));
            Configuration.Localization.Languages.Add(new LanguageInfo("zh-CN", "简体中文", "famfamfam-flag-cn"));
            Configuration.Localization.Languages.Add(new LanguageInfo("ja", "日本語", "famfamfam-flag-jp"));

            //Add/remove localization sources here
            Configuration.Localization.Sources.Add(
                new DictionaryBasedLocalizationSource(
                    STOWaybillMallConsts.LocalizationSourceName,
                    new XmlFileLocalizationDictionaryProvider(
                        HttpContext.Current.Server.MapPath("~/Localization/STOWaybillMall")
                        )
                    )
                );

            //Configure navigation/menu
            //Configuration.Navigation.Providers.Add<STOWaybillMallNavigationProvider>();
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

            //BundleConfig.RegisterBundles(BundleTable.Bundles);
            ConfigureSwaggerUi();

            WebApiConfig.Register(Configuration.Modules.AbpWebApi().HttpConfiguration);

            AreaRegistration.RegisterAllAreas();
            //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            //RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);

        }
        private void ConfigureSwaggerUi()
        {
            Configuration.Modules.AbpWebApi().HttpConfiguration
                .EnableSwagger("docs/{apiVersion}/swagger",c =>
                {
                    var baseDirectory = System.AppDomain.CurrentDomain.BaseDirectory+"bin\\";


                    c.SingleApiVersion("v1", "STOWaybillMall.WebApi").
                    Description("申通面单物料商城")
                    .TermsOfService("河南通通优品科技有限公司");

                    c.IncludeXmlComments(System.IO.Path.Combine(baseDirectory, "STOWaybillMall.Application.xml"));
                    c.IncludeXmlComments(System.IO.Path.Combine(baseDirectory, "STOWaybillMall.WebApi.xml"));
                    c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
                })
                .EnableSwaggerUi(c =>
                {
                    c.InjectJavaScript(Assembly.GetAssembly(typeof(STOWaybillMallWebApiModule)), "STOWaybillMall.Web.Swagger-Custom.js");
                    c.BooleanValues(new[] { "0", "1" });
                    //c.DocExpansion(DocExpansion.None);
                });
        }
    }
}
